package com.mhl.campuscabinet;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.mhl.entity.User;

public class MineFragment extends Fragment implements View.OnClickListener {

    ImageButton myRegister;
    ImageButton mySold;
    ImageButton myBuy;
    ImageButton myStar;
    ImageButton setting;
    TextView username;
    TextView describe;
    ImageView profile;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mine, container, false);
        myRegister = view.findViewById(R.id.my_register);
        mySold = view.findViewById(R.id.my_sold);
        myBuy = view.findViewById(R.id.my_buy);
        myStar = view.findViewById(R.id.my_star);
        setting = view.findViewById(R.id.setting);

        profile = view.findViewById(R.id.profile);
        username = view.findViewById(R.id.username);
        describe = view.findViewById(R.id.describe);

        Glide.with(getActivity()).load("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1" +
                ".zhimg.com%2Fv2-9268cc22c1776a7306f9eda425f946cc_fhd.jpg&refer=http%3A%2F%2Fpic1.zhimg" +
                ".com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt" +
                "=jpeg?sec=1643191504&t=61f0597da86b777ab783cff478b9e091").into(profile);
        username.setText(User.getUsername());
        describe.setText(User.getUserDescription());

        myRegister.setOnClickListener(this);
        mySold.setOnClickListener(this);
        myBuy.setOnClickListener(this);
        myStar.setOnClickListener(this);
        setting.setOnClickListener(this);
        // Inflate the layout for this fragment
        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.my_register:{
                Intent intent = new Intent(getActivity(), MyRegisterActivity.class);
                startActivity(intent);
            }
            break;
            case R.id.my_sold:{
                Intent intent = new Intent(getActivity(), MySoldActivity.class);
                startActivity(intent);
            }
            break;
            case R.id.my_buy:{
                Intent intent = new Intent(getActivity(), MyBuyActivity.class);
                startActivity(intent);
            }
                break;
            case R.id.my_star:{
                Intent intent = new Intent(getActivity(), MyStarActivity.class);
                startActivity(intent);
            }
                break;
            case R.id.setting:{
                Intent intent = new Intent(getActivity(), SettingActivity.class);
                startActivity(intent);
            }
                break;
            default:
                break;
        }
    }
}